﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D3crft.Stats {
    class scStatFunctions {

        public enum eStatEditMode { Add, Substract };
        public enum eStatCharacterMode { EditCharacter, CreateCharacterCopy };

        // ##### Stat IDs :
        // 00: Strength
        // 01: Dexterity
        // 02: Intelligence
        // 03: Vitality
        // 04: Attackspeed Increase %
        // 05: Critical Hit Chance %
        // 06: Critical Hit Damage %
        // 07: Bonus Damage - min
        // 08: Bonus Damage - max
        
        // 10: Lifeleech %
        // 11: Life on Hit
        // 12: Life per second
        // 13: Healthglobe bonus
        // 14: Health per fury spent
        // 15: Health per spirit spent

        // 20: elementary_physical
        // 21: elementary_fire
        // 22: elementary_lightening
        // 23: elementary_cold
        // 24: elementary_holy
        // 28: area dmg
        // 29: bleed dmg
        

        // 30: barb - bash
        // 31: barb - cleave
        // 32: barb - frenzy
        // 33: barb - weapon throw
        // 34: barb - hota
        // 35: barb - rend
        // 36: barb - whirlwind

        // 80: Movespeed Increase %

        // 90: Armor
        // 91: Resistance against all Sources

        public static int GetStatIDByName(string sStatName) {
            switch (sStatName.ToLower()) {
                case "strength":
                    return 0;
                case "dexterity":
                    return 1;
                case "intelligence":
                    return 2;
                case "vitality":
                    return 3;
                case "attackspeed increase %":
                    return 4;
                case "critical hit chance %":
                    return 5;
                case "critical hit damage %":
                    return 6;
                case "bonus damage - min":
                    return 7;
                case "bonus damage - max":
                    return 8;
                default:
                    return -1;
            }
        }

        public static string GetStatNameByID(int iStatID) {
            switch (iStatID) {
                case 0:
                    return "Strength";
                case 1:
                    return "Dexterity";
                case 2:
                    return "Intelligence";
                case 3:
                    return "Vitality";
                case 4:
                    return "Attackspeed Increase %";
                case 5:
                    return "Critical Hit Chance %";
                case 6:
                    return "Critical Hit Damage %";
                case 7:
                    return "Bonus Damage - min";
                case 8:
                    return "Bonus Damage - max";
                default:
                    return null;
            }
        }

        public static Characters.ClassObjects.ocCharacter GetStatChangedCharacter(Characters.ClassObjects.ocCharacter oCharacter, int iStatID, float fStatAmount, eStatEditMode eStatEditMode, eStatCharacterMode eStatCharMode) {
            Characters.ClassObjects.ocCharacter oNewCharacter;

            if (eStatCharMode == eStatCharacterMode.CreateCharacterCopy) {
                oNewCharacter = oCharacter.GetCopy();
            }
            else {
                oNewCharacter = oCharacter;
            }

            if (eStatEditMode == scStatFunctions.eStatEditMode.Add) {
                switch (iStatID) {
                    case 0:
                        oNewCharacter.iBaseStat_Strength += (int)fStatAmount;
                        if (oNewCharacter.iBaseStat_Strength < 0) oNewCharacter.iBaseStat_Strength = 0;
                        break;
                    case 1:
                        oNewCharacter.iBaseStat_Dexterity += (int)fStatAmount;
                        if (oNewCharacter.iBaseStat_Dexterity < 0) oNewCharacter.iBaseStat_Dexterity = 0;
                        break;
                    case 2:
                        oNewCharacter.iBaseStat_Intelligence += (int)fStatAmount;
                        if (oNewCharacter.iBaseStat_Intelligence < 0) oNewCharacter.iBaseStat_Intelligence = 0;
                        break;
                    case 3:
                        oNewCharacter.iBaseStat_Vitality += (int)fStatAmount;
                        if (oNewCharacter.iBaseStat_Vitality < 0) oNewCharacter.iBaseStat_Vitality = 0;
                        break;
                    case 4:
                        oNewCharacter.fOffStat_AttackSpeedInrease += fStatAmount;
                        if (oNewCharacter.fOffStat_AttackSpeedInrease < 0.0f) oNewCharacter.fOffStat_AttackSpeedInrease = 0.0f;
                        break;
                    case 5:
                        oNewCharacter.fOffStat_CritChance += fStatAmount;
                        if (oNewCharacter.fOffStat_CritChance < 0.0f) oNewCharacter.fOffStat_CritChance = 0.0f;
                        break;
                    case 6:
                        oNewCharacter.fOffStat_CritDamage += fStatAmount;
                        if (oNewCharacter.fOffStat_CritDamage < 0.0f) oNewCharacter.fOffStat_CritDamage = 0.0f;
                        break;
                    case 7:
                        oNewCharacter.iOffStat_BonusDamage_Min += (int)fStatAmount;
                        if (oNewCharacter.iOffStat_BonusDamage_Min < 0) oNewCharacter.iOffStat_BonusDamage_Min = 0;
                        break;
                    case 8:
                        oNewCharacter.iOffStat_BonusDamage_Max += (int)fStatAmount;
                        if (oNewCharacter.iOffStat_BonusDamage_Max < 0) oNewCharacter.iOffStat_BonusDamage_Max = 0;
                        break;
                }
            }
            else {
                switch (iStatID) {
                    case 0:
                        oNewCharacter.iBaseStat_Strength -= (int)fStatAmount;
                        if (oNewCharacter.iBaseStat_Strength < 0) oNewCharacter.iBaseStat_Strength = 0;
                        break;
                    case 1:
                        oNewCharacter.iBaseStat_Dexterity -= (int)fStatAmount;
                        if (oNewCharacter.iBaseStat_Dexterity < 0) oNewCharacter.iBaseStat_Dexterity = 0;
                        break;
                    case 2:
                        oNewCharacter.iBaseStat_Intelligence -= (int)fStatAmount;
                        if (oNewCharacter.iBaseStat_Intelligence < 0) oNewCharacter.iBaseStat_Intelligence = 0;
                        break;
                    case 3:
                        oNewCharacter.iBaseStat_Vitality -= (int)fStatAmount;
                        if (oNewCharacter.iBaseStat_Vitality < 0) oNewCharacter.iBaseStat_Vitality = 0;
                        break;
                    case 4:
                        oNewCharacter.fOffStat_AttackSpeedInrease -= fStatAmount;
                        if (oNewCharacter.fOffStat_AttackSpeedInrease < 0.0f) oNewCharacter.fOffStat_AttackSpeedInrease = 0.0f;
                        break;
                    case 5:
                        oNewCharacter.fOffStat_CritChance -= fStatAmount;
                        if (oNewCharacter.fOffStat_CritChance < 0.0f) oNewCharacter.fOffStat_CritChance = 0.0f;
                        break;
                    case 6:
                        oNewCharacter.fOffStat_CritDamage -= fStatAmount;
                        if (oNewCharacter.fOffStat_CritDamage < 0.0f) oNewCharacter.fOffStat_CritDamage = 0.0f;
                        break;
                    case 7:
                        oNewCharacter.iOffStat_BonusDamage_Min -= (int)fStatAmount;
                        if (oNewCharacter.iOffStat_BonusDamage_Min < 0) oNewCharacter.iOffStat_BonusDamage_Min = 0;
                        break;
                    case 8:
                        oNewCharacter.iOffStat_BonusDamage_Max -= (int)fStatAmount;
                        if (oNewCharacter.iOffStat_BonusDamage_Max < 0) oNewCharacter.iOffStat_BonusDamage_Max = 0;
                        break;
                }
            }

            return oNewCharacter;
        }

        public static int GetStatVariableTypeByID(int iStatID) {
            switch (iStatID) {
                case 0:
                    return 1;
                case 1:
                    return 1;
                case 2:
                    return 1;
                case 3:
                    return 1;
                case 4:
                    return 2;
                case 5:
                    return 2;
                case 6:
                    return 2;
                case 7:
                    return 1;
                case 8:
                    return 1;
                default:
                    return -1;
            }
        }
    }
}